home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / fswind_w.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  23KB  |  1,023 lines

  1. /***   [fswind_w.c]
  2. *
  3. *    ファイルセレクタウィンドウ 関連 (ワイド)        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <string.h>
  10. #include <direct.h>
  11. #include <jctype.h>
  12. #include <dos.h>
  13. #include "window.h"
  14. #include "graph.h"
  15. #include "mos.h"
  16. #include "keyin.h"
  17. #include "icn.h"
  18. #include "fswind.h"
  19. #include "beep.h"
  20. #include "others.h"
  21.  
  22. extern int    PAL_Black;
  23. static int    filehd, diroff;
  24. static int    TRIGN, ERROR;
  25. static int    curd, trhd, col;
  26. static struct dirtree_t    dt;
  27. static struct cvars_t    *cv;
  28. static get_f    gf;
  29.  
  30. static void    Draw_window(void);            /* カーソル */
  31. static int    Where(int, int);
  32. static int    Where_drive(int, int);
  33. static int    SUB_drive(int, int);        /* カーソル */
  34. static int    Where_path(int, int);
  35. static int    SUB_path(int, int);            /* カーソル */
  36. static int    Where_file(int, int);
  37. static int    SUB_file(int, int);            /* カーソル */
  38. static void    SUB_scupdw(int);            /* カーソル */
  39. static int    SUB_scupdw_sub(int);
  40. static void    SUB_scdr(int);                /* カーソル */
  41. static void    SUB_move(int, int, struct keyin_t *);    /* カーソル */
  42. static int    Where_kyb(int, int);
  43. static void    SUB_kyb(int, int);            /* カーソル */
  44. static void    allcls(void);                /* カーソル */
  45. static void    errord(void);                /* カーソル */
  46. static int    tree_break(void);
  47. static void    Tree(int);                    /* カーソル */
  48. static void    SUB_trscudV(int);            /* カーソル */
  49. static int    SUB_trscudV_sub(int);
  50. static void    SUB_trscudH(int);            /* カーソル */
  51. static int    SUB_trscudH_sub(int);
  52. static void    trbrd(void);                /* カーソル */
  53. static void    SUB_trscdrV(int);            /* カーソル */
  54. static void    SUB_trscdrH(int);            /* カーソル */
  55. static int    SUB_tree(int, int);            /* カーソル */
  56. static int    Where_tree(int, int);
  57.  
  58. int WIND_file_w(char *path, struct cvars_t    *cvars) {
  59.     int        ret = 0, ret2 = 0;
  60.     struct keyin_t    kt;
  61.     
  62.     ERROR = 0;
  63.     TRIGN = 0;
  64.     cv = cvars;
  65.     
  66.     kt.x = cv->wx + 520;
  67.     kt.y = cv->wy + 347 + 20 * cv->drw;
  68.     kt.keta = 14;
  69.     kt.foreC = PAL_Black;
  70.     kt.backC = 7;
  71.     kt.curC = 10;
  72.     kt.buf = path;
  73.     kt.bufn = 80;
  74.     Draw_window();
  75.     Keyin_init(&kt);
  76.     
  77.     ICN_mos(1);
  78.     if (FSW_Draw_path(0, &diroff)) {
  79.         errord();
  80.     } else if (FSW_Draw_volid(0), FSW_Draw_diskfree(0)) {
  81.         errord();
  82.     } else {
  83.         int        dm1;
  84.         char    dm2;
  85.         
  86.         filehd = 0;
  87.         if (FSW_Draw_file(0, filehd, &gf))
  88.             return -1;
  89.         FSW_Draw_scrollB(filehd, gf.nfiles);
  90.         MOS_rdon(1, &dm2, &dm1, &dm1, &dm1);
  91.         MOS_rdopen(1, &dm2, &dm1, &dm1, &dm1);
  92.         switch (Get_dirtree(&dt, cv->cap, tree_break)) {
  93.             case -1:
  94.                 return -1;
  95.                 break;
  96.             case -2:
  97.                 errord();
  98.                 break;
  99.             case -3:
  100.                 trbrd();
  101.                 break;
  102.             default:
  103.                 if (!TR_Search_curd(1, &curd, cv->dirbuf, &dt)) {
  104.                     errord();
  105.                 } else {
  106.                     trhd = 0;
  107.                     col = 0;
  108.                     Tree(0);
  109.                 }
  110.                 break;
  111.         }
  112.     }
  113.     ICN_mos(0);
  114.     
  115.     while (!ret && ret2 != 1) {
  116.         char    mb;
  117.         int        wh, mx, my;
  118.         
  119.         if ((ret2 = Keyin()) == -1)
  120.             Keyin_init(&kt);
  121.         
  122.         CLOCK(0);
  123.         if (MOS_rdpos(&mb, &mx, &my), !(mb & 1))
  124.             continue;
  125.         
  126.         if (wh = Where(mx, my), wh != WH_END && wh != WH_TITLE && wh != WH_OPT1 && wh != WH_OPT2 && wh != WH_DRIVE && wh != WH_KYB && wh != WH_OTHER) {
  127.             if (!ERROR) {
  128.                 switch (wh) {
  129.                     int        sc;
  130.                     
  131.                     case WH_PATH:
  132.                         if (SUB_path(mx, my))
  133.                             ret = -1;
  134.                         break;
  135.                     case WH_SCUP:
  136.                         SUB_scupdw(1);
  137.                         break;
  138.                     case WH_SCDW:
  139.                         SUB_scupdw(0);
  140.                         break;
  141.                     case WH_SCDR:
  142.                         SUB_scdr(my);
  143.                         break;
  144.                     case WH_FILE:
  145.                         if ((sc = SUB_file(mx, my)) == -2) {
  146.                             ret = -1;
  147.                         } else if (sc >= 0) {
  148.                             strlow(1, (gf.pbuf[filehd + sc])->name);
  149.                             strcpy(path, cv->dirbuf);
  150.                             if (((char *)strchr(path, '\0'))[-1] != '\\')
  151.                                 strcat(path, "\\");
  152.                             strcat(path, (char *)(gf.pbuf[filehd + sc])->name);
  153.                             ret = 1;
  154.                         }
  155.                         break;
  156.                     case WH_TRSCUPV:
  157.                         SUB_trscudV(1);
  158.                         break;
  159.                     case WH_TRSCDWV:
  160.                         SUB_trscudV(0);
  161.                         break;
  162.                     case WH_TRSCDRV:
  163.                         SUB_trscdrV(my);
  164.                         break;
  165.                     case WH_TRSCUPH:
  166.                         SUB_trscudH(1);
  167.                         break;
  168.                     case WH_TRSCDWH:
  169.                         SUB_trscudH(0);
  170.                         break;
  171.                     case WH_TRSCDRH:
  172.                         SUB_trscdrH(mx);
  173.                         break;
  174.                     case WH_TR:
  175.                         if (SUB_tree(mx, my))
  176.                             ret = -1;
  177.                         break;
  178.                 }
  179.             }
  180.         } else {
  181.             switch (wh) {
  182.                 case WH_END:
  183.                     if (FSW_end())
  184.                         ret = 2;
  185.                     break;
  186.                 case WH_TITLE:
  187.                     SUB_move(mx, my, &kt);
  188.                     break;
  189.                 case WH_OPT1:
  190.                     if (FSW_opt1())
  191.                         ret = 3;
  192.                     break;
  193.                 case WH_OPT2:
  194.                     if (FSW_opt2(&mx, &my)) {
  195.                         cv->sort = my;
  196.                         if (!ERROR) {
  197.                             filehd = 0;
  198.                             FSW_Draw_file(2, filehd, &gf);
  199.                             FSW_Draw_scrollB(filehd, gf.nfiles);
  200.                         }
  201.                     }
  202.                     break;
  203.                 case WH_DRIVE:
  204.                     if (SUB_drive(mx, my))
  205.                         ret = -1;
  206.                     break;
  207.                 case WH_KYB:
  208.                     SUB_kyb(mx, my);
  209.                     break;
  210.                 case WH_OTHER:
  211.                     do {
  212.                         MOS_rdpos(&mb, &mx, &my);
  213.                     } while (mb & 1);
  214.                     break;
  215.             }
  216.         }
  217.     }
  218.     
  219.     Gf_bufrel();
  220.     TR_bufrel();
  221.     if (ret == -1)
  222.         return -1;
  223.     else if (ret == 2)
  224.         return 0;
  225.     else if (ret == 3)
  226.         return 2;
  227.     else
  228.         return 1;
  229. }
  230.  
  231. static void Draw_window(void) {
  232.     int        a;
  233.     struct opnwin_t    opw;
  234.     static const int    optw[] = {
  235.         2, 2
  236.     };
  237.     
  238.     a = 20 * cv->drw;
  239.     opw.title = cv->title;
  240.     opw.x1 = cv->wx;
  241.     opw.y1 = cv->wy;
  242.     opw.x2 = opw.x1 + 639;
  243.     opw.y2 = opw.y1 + 355 + a;
  244.     opw.canb = 1;
  245.     opw.nopt = 2;
  246.     opw.wopt = optw;
  247.     opw.expb = 0;
  248.     opw.shdw = 1;
  249.     opw.ord = 0;
  250.     MOS_disp(0);
  251.     drawWindow(&opw);
  252.     
  253.     EGB_line(cv->wx + 5, cv->wy + 27 + a, cv->wx + 634, cv->wy + 27 + a, PAL_Black);
  254.     EGB_line(cv->wx + 249, cv->wy + 48 + a, cv->wx + 634, cv->wy + 48 + a, PAL_Black);
  255.     EGB_line(cv->wx + 249, cv->wy + 27 + a, cv->wx + 249, cv->wy + 329 + a, PAL_Black);
  256.     EGB_line(cv->wx + 5, cv->wy + 329 + a, cv->wx + 634, cv->wy + 329 + a, PAL_Black);
  257.     EGB_line(cv->wx + 517, cv->wy + 329 + a, cv->wx + 517, cv->wy + 350 + a, PAL_Black);
  258.     
  259.     DrawScrollbar(0, cv->wx + 233, cv->wy + 27 + a, 287);
  260.     DrawScrollbar(1, cv->wx + 5, cv->wy + 313 + a, 229);
  261.     DrawScrollbar(0, cv->wx + 618, cv->wy + 48 + a, 282);
  262.     ICN_opt(0, cv->wx + 616, cv->wy + 8);
  263.     EGB_str2("★", cv->wx + 595, cv->wy + 23, PAL_Black);
  264.     FSW_Draw_drive();
  265.     MOS_disp(1);
  266. }
  267.  
  268. static int Where_drive(int x, int y) {
  269.     int        i = 0, xx, yy;
  270.     
  271.     x -= cv->wx;
  272.     y -= cv->wy;
  273.     for (yy = 0; yy < cv->drw; yy++) {
  274.         for (xx = 0; xx < 11; xx++) {
  275.             if (i >= cv->drinfo[0])
  276.                 return -1;
  277.             else if (xx * 57 + 28 < x && x < xx * 57 + 56 && yy * 20 + 29 < y && y < yy * 20 + 44)
  278.                 return i;
  279.             else
  280.                 i++;
  281.         }
  282.     }
  283.     
  284.     return -1;
  285. }
  286.  
  287. static int SUB_drive(int x, int y) {
  288.     int        psc;
  289.     
  290.     if ((psc = Where_drive(x, y)) == -1) {
  291.         char    mb;
  292.         
  293.         do {
  294.             int        mx, my;
  295.             
  296.             MOS_rdpos(&mb, &mx, &my);
  297.         } while (mb & 1);
  298.         return 0;
  299.     }
  300.     
  301.     x = psc % 11;
  302.     y = psc / 11;
  303.     x = cv->wx + x * 57 + 29;
  304.     y = cv->wy + y * 20 + 30;
  305.     if (Button(x, y, x + 26, y + 13)) {
  306.         unsigned    dr;
  307.         
  308.         EGB_rev(1, x, y, x + 26, y + 13);
  309.         ICN_mos(1);
  310.         allcls();
  311.         _dos_setdrive(cv->drinfo[psc * 2 + 1] - 'A' + 1, &dr);
  312.         if (FSW_Draw_path(0, &diroff)) {
  313.             errord();
  314.         } else if (FSW_Draw_volid(0), FSW_Draw_diskfree(0)) {
  315.             errord();
  316.         } else {
  317.             int        dm1;
  318.             char    dm2;
  319.             
  320.             ERROR = 0;
  321.             TRIGN = 0;
  322.             filehd = 0;
  323.             if (FSW_Draw_file(0, filehd, &gf))
  324.                 return -1;
  325.             FSW_Draw_scrollB(filehd, gf.nfiles);
  326.             MOS_rdon(1, &dm2, &dm1, &dm1, &dm1);
  327.             MOS_rdopen(1, &dm2, &dm1, &dm1, &dm1);
  328.             switch(Get_dirtree(&dt, cv->cap, tree_break)) {
  329.                 case -1:
  330.                     return -1;
  331.                     break;
  332.                 case -2:
  333.                     errord();
  334.                     break;
  335.                 case -3:
  336.                     trbrd();
  337.                     break;
  338.                 default:
  339.                     if (!TR_Search_curd(1, &curd, cv->dirbuf, &dt)) {
  340.                         errord();
  341.                     } else {
  342.                         trhd = 0;
  343.                         col = 0;
  344.                         Tree(0);
  345.                     }
  346.                     break;
  347.             }
  348.         }
  349.         ICN_mos(0);
  350.     }
  351.     
  352.     return 0;
  353. }
  354.  
  355. static int SUB_path(int mx, int my) {
  356.     int        sc, psc = -1;
  357.     int        xx, yy;
  358.     char    mb;
  359.     
  360.     ICN_mos(2);
  361.     sc = Where_path(mx, my);
  362.     
  363.     xx = cv->wx + 258;
  364.     yy = cv->wy + 30 + 20 * cv->drw;
  365.     do {
  366.         if (sc != -1) {
  367.             if (diroff == 0 && sc <= 2) {
  368.                 sc = 2;
  369.             } else {
  370.                 do {
  371.                     sc++;
  372.                 } while (sc < strlen(cv->dirbuf2) && cv->dirbuf2[sc] != '\\');
  373.                 sc--;
  374.             }
  375.         }
  376.         if (sc == -1 && psc != sc)
  377.             EGB_rev(1, xx, yy, xx + (psc + 1) * 8 - 1, yy + 15);
  378.         else if (sc > psc)
  379.             EGB_rev(1, xx + (psc + 1) * 8, yy, xx + (sc + 1) * 8 - 1, yy + 15);
  380.         else if (sc < psc)
  381.             EGB_rev(1, xx + (sc + 1) * 8, yy, xx + (psc + 1) * 8 - 1, yy + 15);
  382.         psc = sc;
  383.         
  384.         MOS_rdpos(&mb, &mx, &my);
  385.         sc = Where_path(mx, my);
  386.     } while (mb & 1);
  387.     ICN_mos(0);
  388.     
  389.     if (psc != -1) {
  390.         if (diroff != 0)
  391.             cv->dirbuf[diroff + psc - 4] = '\0';
  392.         else
  393.             cv->dirbuf[diroff + psc + 1] = '\0';
  394.         if (strlen(cv->dirbuf) < 3)
  395.             strcpy(cv->dirbuf + 2, "\\");
  396.         ICN_mos(1);
  397.         if (chdir(cv->dirbuf)) {
  398.             errord();
  399.         } else if (FSW_Draw_path(0, &diroff)) {
  400.             errord();
  401.         } else if (!TRIGN && !TR_Search_curd(1, &curd, cv->dirbuf, &dt)) {
  402.             errord();
  403.         } else {
  404.             Tree(1);
  405.             filehd = 0;
  406.             if (FSW_Draw_file(0, filehd, &gf))
  407.                 return -1;
  408.             FSW_Draw_scrollB(filehd, gf.nfiles);
  409.         }
  410.         ICN_mos(0);
  411.     }
  412.     
  413.     return 0;
  414. }
  415.  
  416. static int Where_path(int x, int y) {
  417.     int        sc, ret;
  418.     
  419.     x -= cv->wx;
  420.     y -= cv->wy;
  421.     if (x < 258 || 626 < x || y < 30 + 20 * cv->drw || 45 + 20 * cv->drw < y) {
  422.         ret = -1;
  423.     } else {
  424.         sc = (x - 258) / 8;
  425.         if (strlen(cv->dirbuf2) > sc)
  426.             ret = sc;
  427.         else
  428.             ret = -1;
  429.     }
  430.     
  431.     return ret;
  432. }
  433.  
  434. static void SUB_scupdw(int w) {
  435.     int        xx, yy, mx, my, fllast, flpush = 1;
  436.     char    mb;
  437.     
  438.     if (w) {
  439.         xx = cv->wx + 619;
  440.         yy = cv->wy + 49 + 20 * cv->drw;
  441.     } else {
  442.         xx = cv->wx + 619;
  443.         yy = cv->wy + 314 + 20 * cv->drw;
  444.     }
  445.     
  446.     EGB_rev(1, xx, yy, xx + 14, yy + 14);
  447.     fllast = SUB_scupdw_sub(w);
  448.     TIMER_set(20);
  449.     
  450.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  451.         int        whres;
  452.         
  453.         whres = Where(mx, my) == (w ? WH_SCUP : WH_SCDW);
  454.         if (!whres && flpush || whres && !flpush) {
  455.             EGB_rev(1, xx, yy, xx + 14, yy + 14);
  456.             flpush = !flpush;
  457.         }
  458.         
  459.         if (flpush && TIMER() && !fllast)
  460.             fllast = SUB_scupdw_sub(w);
  461.     }
  462.     
  463.     if (flpush)
  464.         EGB_rev(1, xx, yy, xx + 14, yy + 14);
  465. }
  466.  
  467. static int SUB_scupdw_sub(int w) {
  468.     if (!(w && filehd > 0 || !w && filehd + 14 < gf.nfiles))
  469.         return 1;
  470.     
  471.     w ? filehd-- : filehd++;
  472.     FSW_Draw_scrollB(filehd, gf.nfiles);
  473.     EGB_color(EGB_work, EGB_COL_BACK, 7);
  474.     MOS_disp(0);
  475.     EGB_scrl(1, cv->wx + 258, cv->wy + 49 + 20 * cv->drw, cv->wx + 612, cv->wy + 328 + 20 * cv->drw, 0, w ? 20 : -20);
  476.     FSW_Draw_file_sub(w ? 0 : 13, filehd, &gf);
  477.     MOS_disp(1);
  478.     
  479.     return 0;
  480. }
  481.  
  482. static void SUB_scdr(int my) {
  483.     int        mx, y;
  484.     char    mb;    
  485.     struct sb_t    sb;
  486.     
  487.     ICN_mos(3);
  488.     y = cv->wy + 65 + 20 * cv->drw;
  489.     sb.tl = gf.nfiles;    sb.lpp = 14;
  490.     sb.blen = 248;        sb.bml = 15;
  491.     SCRB_bar(&sb, my - y, &filehd);
  492.     
  493.     FSW_Draw_scrollB(filehd, gf.nfiles);
  494.     FSW_Draw_file(1, filehd, &gf);
  495.     
  496.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  497.         int        a, f;
  498.         
  499.         if (Where(mx, my) != WH_SCDR)
  500.             continue;
  501.         if (SCRB_bar(&sb, my - y, &a), a == filehd)
  502.             continue;
  503.         
  504.         f = a < filehd;
  505.         filehd += f ? -1 : 1;
  506.         FSW_Draw_scrollB(filehd, gf.nfiles);
  507.         EGB_color(EGB_work, EGB_COL_BACK, 7);
  508.         MOS_disp(0);
  509.         EGB_scrl(1, cv->wx + 258, cv->wy + 49 + 20 * cv->drw, cv->wx + 612, cv->wy + 328 + 20 * cv->drw, 0, f ? 20 : -20);
  510.         FSW_Draw_file_sub(f ? 0 : 13, filehd, &gf);
  511.         MOS_disp(1);
  512.     }
  513.     ICN_mos(0);
  514. }
  515.  
  516. static int SUB_file(int mx, int my) {
  517.     int        sc, xx, yy, ret, psc = -1;
  518.     char    mb;
  519.     
  520.     xx = cv->wx + 250;
  521.     yy = cv->wy + 49 + 20 * cv->drw;
  522.     sc = Where_file(mx, my);
  523.     do {
  524.         if (psc != sc) {
  525.             if (psc != -1)
  526.                 EGB_rev(1, xx, yy + psc * 20, xx + 367, yy + (psc + 1) * 20 - 1);
  527.             if (sc != -1)
  528.                 EGB_rev(1, xx, yy + sc * 20, xx + 367, yy + (sc + 1) * 20 - 1);
  529.         }
  530.         psc = sc;
  531.         
  532.         MOS_rdpos(&mb, &mx, &my);
  533.         sc = Where_file(mx, my);
  534.     } while (mb & 1);
  535.     
  536.     if (psc == -1) {
  537.         ret = -1;
  538.     } else if ((gf.pbuf[filehd + sc])->attr & _A_SUBDIR) {
  539.         ICN_mos(1);
  540.         if (chdir((char *)(gf.pbuf[filehd + sc])->name)) {
  541.             errord();
  542.         } else if (FSW_Draw_path(0, &diroff)) {
  543.             errord();
  544.         } else if (!TRIGN && !TR_Search_curd(1, &curd, cv->dirbuf, &dt)) {
  545.             errord();
  546.         } else {
  547.             Tree(1);
  548.             filehd = 0;
  549.             if (FSW_Draw_file(0, filehd, &gf))
  550.                 ret = -2;
  551.             FSW_Draw_scrollB(filehd, gf.nfiles);
  552.         }
  553.         ICN_mos(0);
  554.         
  555.         ret = -1;
  556.     } else {
  557.         int    i;
  558.         
  559.         for (i = 0;i < 4;i++) {
  560.             for (TIMER_set(5); !TIMER(); );
  561.             EGB_rev(1, xx, yy + psc * 20, xx + 367, yy + (psc + 1) * 20 - 1);
  562.         }
  563.         ret = sc;
  564.     }
  565.     
  566.     return ret;
  567. }
  568.  
  569. static int Where_file(int mx, int my) {
  570.     int        ret;
  571.     
  572.     mx -= cv->wx;
  573.     my -= cv->wy;
  574.     if (mx < 250 || 617 < mx || my < 49 + 20 * cv->drw || 328 + 20 * cv->drw < my) {
  575.         ret = -1;
  576.     } else {
  577.         int        sc;
  578.         
  579.         sc = (my - (49 + 20 * cv->drw)) / 20;
  580.         if (filehd + sc < gf.nfiles)
  581.             ret = sc;
  582.         else
  583.             ret = -1;
  584.     }
  585.     
  586.     return ret;
  587. }
  588.  
  589. static int Where(int x, int y) {
  590.     int        a, i, ret = WH_OTHER;
  591.     static const short    table[19][7] = {
  592.         {5, 26, 5, 26, 0, 0, WH_END},    {26, 592, 5, 26, 0, 0, WH_TITLE},
  593.         {613, 634, 5, 26, 0, 0, WH_OPT1},    {592, 613, 5, 26, 0, 0, WH_OPT2},
  594.         {5, 634, 26, 27, 0, 1, WH_DRIVE},    {249, 634, 27, 48, 1, 1, WH_PATH},
  595.         {249, 618, 48, 329, 1, 1, WH_FILE},    {618, 634, 48, 64, 1, 1, WH_SCUP},
  596.         {618, 634, 64, 313, 1, 1, WH_SCDR},    {618, 634, 313, 329, 1, 1, WH_SCDW},
  597.         {5, 517, 329, 350, 1, 1, WH_FREE},    {517, 634, 329, 350, 1, 1, WH_KYB},
  598.         {233, 249, 27, 43, 1, 1, WH_TRSCUPV},    {233, 249, 43, 297, 1, 1, WH_TRSCDRV},
  599.         {233, 249, 297, 313, 1, 1, WH_TRSCDWV},    {5, 21, 313, 329, 1, 1, WH_TRSCUPH},
  600.         {21, 217, 313, 329, 1, 1, WH_TRSCDRH},    {217, 233, 313, 329, 1, 1, WH_TRSCDWH},
  601.         {5, 233, 27, 313, 1, 1, WH_TR}
  602.     };
  603.     
  604.     x -= cv->wx;
  605.     y -= cv->wy;
  606.     a = 20 * cv->drw;
  607.     for (i = 0; i < 19; i++) {
  608.         const short    *p;
  609.         
  610.         p = table[i];
  611.         if (p[0] < x && x < p[1] && p[2] + (p[4] ? a : 0) < y && y < p[3] + (p[5] ? a : 0)) {
  612.             ret = p[6];
  613.             break;
  614.         }
  615.     }
  616.     
  617.     return ret;
  618. }
  619.  
  620. static void SUB_move(int x, int y, struct keyin_t *kt) {
  621.     struct RECT    s, w;
  622.     
  623.     w.x1 = cv->wx;    w.y1 = cv->wy;
  624.     w.x2 = cv->wx + 639;    w.y2 = cv->wy + 355 + 20 * cv->drw;
  625.     s.x1 = 0;    s.y1 = 40;    s.x2 = 639;    s.y2 = 463;
  626.     if (dragWindow(x, y, &w, &s, 0, 0)) {
  627.         cv->wx = w.x1;    cv->wy = w.y1;
  628.         MOS_disp(0);
  629.         EGB_cls(0);
  630.         ICN_mos(0);
  631.         MOS_disp(1);
  632.         kt->x = cv->wx + 520;
  633.         kt->y = cv->wy + 347 + 20 * cv->drw;
  634.         Draw_window();
  635.         Keyin_redisp();
  636.         if (ERROR) {
  637.             errord();
  638.         } else {
  639.             FSW_Draw_path(1, &diroff);
  640.             FSW_Draw_volid(1);
  641.             FSW_Draw_diskfree(1);
  642.             Tree(0);
  643.             FSW_Draw_file(1, filehd, &gf);
  644.             FSW_Draw_scrollB(filehd, gf.nfiles);
  645.         }
  646.     }
  647. }
  648.  
  649. static void SUB_kyb(int mx, int my) {
  650.     int        sc;
  651.     char    mb;
  652.     
  653.     ICN_mos(2);
  654.     sc = Where_kyb(mx, my);
  655.     do {
  656.         Keyin_cur(sc);
  657.         MOS_rdpos(&mb, &mx, &my);
  658.         sc = Where_kyb(mx, my);
  659.     } while (mb & 1);
  660.     ICN_mos(0);
  661. }
  662.  
  663. static int Where_kyb(int x, int y) {
  664.     int        ret;
  665.     
  666.     x -= cv->wx;
  667.     y -= cv->wy;
  668.     if (x < 520 || 631 < x || y < 332 + 20 * cv->drw || 347 + 20 * cv->drw < y)
  669.         ret = -1;
  670.     else
  671.         ret = (x - 520) / 8;
  672.     
  673.     return ret;
  674. }
  675.  
  676. static void allcls(void) {
  677.     int        a;
  678.     
  679.     a = 20 * cv->drw;
  680.     MOS_disp(0);
  681.     EGB_boxf(cv->wx + 5, cv->wy + 27 + a, cv->wx + 233, cv->wy + 313 + a, PAL_Black, 7);
  682.     EGB_boxf(cv->wx + 233, cv->wy + 43 + a, cv->wx + 249, cv->wy + 297 + a, PAL_Black, 6);
  683.     EGB_boxf(cv->wx + 21, cv->wy + 313 + a, cv->wx + 217, cv->wy + 329 + a, PAL_Black, 6);
  684.     EGB_boxf(cv->wx + 249, cv->wy + 27 + a, cv->wx + 634, cv->wy + 48 + a, PAL_Black, 7);
  685.     EGB_boxf(cv->wx + 249, cv->wy + 48 + a, cv->wx + 618, cv->wy + 329 + a, PAL_Black, 7);
  686.     EGB_boxf(cv->wx + 618, cv->wy + 64 + a, cv->wx + 634, cv->wy + 313 + a, PAL_Black, 6);
  687.     EGB_boxf(cv->wx + 5, cv->wy + 329 + a, cv->wx + 517, cv->wy + 350 + a, PAL_Black, 7);
  688.     MOS_disp(1);
  689. }
  690.  
  691. static void errord(void) {
  692.     int        x, y;
  693.     char    buf[5];
  694.     
  695.     allcls();
  696.     FSW_getdrive(buf);
  697.     MOS_disp(0);
  698.     EGB_str2(buf, cv->wx + 258, cv->wy + 45 + 20 * cv->drw, PAL_Black);
  699.     x = cv->wx + 290;
  700.     y = cv->wy + 48 + 20 * cv->drw;
  701.     EGB_str2("ディスクの有無を確認して", x, y + 130, PAL_Black);
  702.     EGB_str2("  ドライブを選択しなおしてください", x, y + 150, PAL_Black);
  703.     MOS_disp(1);
  704.     BEP_on();
  705.     ERROR = 1;
  706. }
  707.  
  708. static int tree_break(void) {
  709.     int        ret, m2, dm;
  710.     char    m1;
  711.     
  712.     if (MOS_rdon(1, &m1, &m2, &dm, &dm), m1 & 2 || m2)
  713.         ret = 1;
  714.     else if (MOS_rdopen(1, &m1, &m2, &dm, &dm), m1 & 2 || m2)
  715.         ret = 1;
  716.     else
  717.         ret = 0;
  718.     
  719.     return ret;
  720. }
  721.  
  722. static void Tree(int mode) {
  723.     struct tree_t    *tr;
  724.     static int    pcurd;
  725.     
  726.     if (TRIGN)
  727.         return;
  728.     
  729.     tr = dt.tr + curd;
  730.     if (4 * col < 4 * tr->nest + strlen(tr->name) - 24) {
  731.         col = (4 * tr->nest + strlen(tr->name) - 24) / 4 + 1;
  732.         mode = 0;
  733.     } else if (tr->nest < col) {
  734.         col = tr->nest - 1;
  735.         mode = 0;
  736.     }
  737.     if (curd < trhd) {
  738.         trhd = curd - 1;
  739.         mode = 0;
  740.     } else if (curd > trhd + 13) {
  741.         trhd = curd - 12;
  742.         mode = 0;
  743.     }
  744.     if (col > dt.numc - 3)
  745.         col = dt.numc - 3;
  746.     if (col < 0)
  747.         col = 0;
  748.     if (trhd + 14 > dt.numd)
  749.         trhd = dt.numd - 14;
  750.     if (trhd < 0)
  751.         trhd = 0;
  752.     
  753.     if (mode) {
  754.         int        x, y;
  755.         struct tree_t    *tr2;
  756.         
  757.         tr2 = dt.tr + pcurd;
  758.         x = cv->wx + 7 - 32 * col;
  759.         y = cv->wy + 30 + 20 * cv->drw - 20 * trhd;
  760.         MOS_disp(0);
  761.         EGB_view(cv->wx + 7, cv->wy + 30 + 20 * cv->drw, cv->wx + 230, cv->wy + 309 + 20 * cv->drw);
  762.         EGB_rev(1, x + 32 * tr2->nest, y + 20 * pcurd, x + (4 * tr2->nest + strlen(tr2->name) + 4) * 8 - 1, y + 20 * pcurd + 19);
  763.         EGB_rev(1, x + 32 * tr->nest, y + 20 * curd, x + (4 * tr->nest + strlen(tr->name) + 4) * 8 - 1, y + 20 * curd + 19);
  764.         EGB_view(0, 0, 1023, 511);
  765.         MOS_disp(1);
  766.     } else {
  767.         FSW_Draw_tree(trhd, col, &dt, curd);
  768.     }
  769.     pcurd = curd;
  770. }
  771.  
  772. static void SUB_trscudV(int w) {
  773.     int        xx, yy, mx, my, fllast, flpush = 1;
  774.     char    mb;
  775.     
  776.     if (TRIGN)
  777.         return;
  778.     
  779.     if (w) {
  780.         xx = cv->wx + 234;
  781.         yy = cv->wy + 28 + 20 * cv->drw;
  782.     } else {
  783.         xx = cv->wx + 234;
  784.         yy = cv->wy + 298 + 20 * cv->drw;
  785.     }
  786.     
  787.     EGB_rev(1, xx, yy, xx + 14, yy + 14);
  788.     fllast = SUB_trscudV_sub(w);
  789.     TIMER_set(20);
  790.     
  791.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  792.         int        whres;
  793.         
  794.         whres = Where(mx, my) == (w ? WH_TRSCUPV : WH_TRSCDWV);
  795.         if (!whres && flpush || whres && !flpush) {
  796.             EGB_rev(1, xx, yy, xx + 14, yy + 14);
  797.             flpush = !flpush;
  798.         }
  799.         
  800.         if (flpush && TIMER() && !fllast)
  801.         fllast = SUB_trscudV_sub(w);
  802.     }
  803.     
  804.     if (flpush)
  805.         EGB_rev(1, xx, yy, xx + 14, yy + 14);
  806. }
  807.  
  808. static int SUB_trscudV_sub(int w) {
  809.     if (!(w && trhd > 0 || !w && trhd + 14 < dt.numd))
  810.         return 1;
  811.     
  812.     w ? trhd-- : trhd++;
  813.     FSW_Draw_trscrlB(1, trhd, dt.numd, col, dt.numc);
  814.     EGB_color(EGB_work, EGB_COL_BACK, 7);
  815.     MOS_disp(0);
  816.     EGB_scrl(1, cv->wx + 7, cv->wy + 30 + 20 * cv->drw, cv->wx + 230, cv->wy + 309 + 20 * cv->drw, 0, w ? 20 : -20);
  817.     FSW_Draw_tree_line(trhd, col, w ? 0 : 13, &dt, curd);
  818.     MOS_disp(1);
  819.     
  820.     return 0;
  821. }
  822.  
  823. static void SUB_trscudH(int w) {
  824.     int        xx, yy, mx, my, fllast, flpush = 1;
  825.     char    mb;
  826.     
  827.     if (TRIGN)
  828.         return;
  829.     
  830.     if (w) {
  831.         xx = cv->wx + 6;
  832.         yy = cv->wy + 314 + 20 * cv->drw;
  833.     } else {
  834.         xx = cv->wx + 218;
  835.         yy = cv->wy + 314 + 20 * cv->drw;
  836.     }
  837.     
  838.     EGB_rev(1, xx, yy, xx + 14, yy + 14);
  839.     fllast = SUB_trscudH_sub(w);
  840.     TIMER_set(20);
  841.     
  842.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  843.         int        whres;
  844.         
  845.         whres = Where(mx, my) == (w ? WH_TRSCUPH : WH_TRSCDWH);
  846.         if (!whres && flpush || whres && !flpush) {
  847.             EGB_rev(1, xx, yy, xx + 14, yy + 14);
  848.             flpush = !flpush;
  849.         }
  850.         
  851.         if (flpush && TIMER() && !fllast)
  852.         fllast = SUB_trscudH_sub(w);
  853.     }
  854.     
  855.     if (flpush)
  856.         EGB_rev(1, xx, yy, xx + 14, yy + 14);
  857. }
  858.  
  859. static int SUB_trscudH_sub(int w) {
  860.     int        i, y;
  861.     
  862.     if (!(w && col > 0 || !w && col + 7 < dt.numc + 3))
  863.         return 0;
  864.     
  865.     y = cv->wy + 30 + 20 * cv->drw;
  866.     w ? col-- : col++;
  867.     FSW_Draw_trscrlB(0, trhd, dt.numd, col, dt.numc);
  868.     MOS_disp(0);
  869.     for (i = 0; i < 14; i++) {
  870.         EGB_boxf(cv->wx + 7, y + 20 * i, cv->wx + 230, y + 20 * i + 19, 7, 7);
  871.         FSW_Draw_tree_line(trhd, col, i, &dt, curd);
  872.     }
  873.     MOS_disp(1);
  874.     
  875.     return 1;
  876. }
  877.  
  878. static void trbrd(void) {
  879.     MOS_disp(0);
  880.     ICN_tree(cv->wx + 103, cv->wy + 154 + 20 * cv->drw);
  881.     MOS_disp(1);
  882.     TRIGN = 1;
  883. }
  884.  
  885. static void SUB_trscdrV(int my) {
  886.     int        y, mx;
  887.     char    mb;    
  888.     struct sb_t    sb;
  889.     
  890.     if (TRIGN)    return;
  891.     
  892.     ICN_mos(3);
  893.     y = cv->wy + 44 + 20 * cv->drw;
  894.     sb.tl = dt.numd;    sb.lpp = 14;
  895.     sb.blen = 253;        sb.bml = 15;
  896.     SCRB_bar(&sb, my - y, &trhd);
  897.     
  898.     FSW_Draw_tree(trhd, col, &dt, curd);
  899.     
  900.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  901.         int        a, f;
  902.         
  903.         if (Where(mx, my) != WH_TRSCDRV)
  904.             continue;
  905.         if (SCRB_bar(&sb, my - y, &a), a == trhd)
  906.             continue;
  907.         
  908.         f = a < trhd;
  909.         trhd += f ? -1 : 1;
  910.         FSW_Draw_trscrlB(1, trhd, dt.numd, col, dt.numc);
  911.         EGB_color(EGB_work, EGB_COL_BACK, 7);
  912.         MOS_disp(0);
  913.         EGB_scrl(1, cv->wx + 7, cv->wy + 30 + 20 * cv->drw, cv->wx + 230, cv->wy + 309 + 20 * cv->drw, 0, f ? 20 : -20);
  914.         FSW_Draw_tree_line(trhd, col, f ? 0 : 13, &dt, curd);
  915.         MOS_disp(1);
  916.     }
  917.     ICN_mos(0);
  918. }
  919.  
  920. static void SUB_trscdrH(int mx) {
  921.     int        x, y, my;
  922.     char    mb;    
  923.     struct sb_t    sb;
  924.     
  925.     if (TRIGN)    return;
  926.     
  927.     ICN_mos(3);
  928.     x = cv->wx + 22;
  929.     y = cv->wy + 30 + 20 * cv->drw;
  930.     sb.tl = dt.numc + 3;    sb.lpp = 7;
  931.     sb.blen = 195;        sb.bml = 15;
  932.     SCRB_bar(&sb, mx - x, &col);
  933.     
  934.     FSW_Draw_tree(trhd, col, &dt, curd);
  935.     
  936.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  937.         int        i, a, f;
  938.         
  939.         if (Where(mx, my) != WH_TRSCDRH)
  940.             continue;
  941.         if (SCRB_bar(&sb, mx - x, &a), a == col)
  942.             continue;
  943.         
  944.         f = a < col;
  945.         col += f ? -1 : 1;
  946.         FSW_Draw_trscrlB(0, trhd, dt.numd, col, dt.numc);
  947.         EGB_color(EGB_work, EGB_COL_BACK, 7);
  948.         MOS_disp(0);
  949.         for (i = 0; i < 14; i++) {
  950.             EGB_boxf(cv->wx + 7, y + 20 * i, cv->wx + 230, y + 20 * i + 19, 7, 7);
  951.             FSW_Draw_tree_line(trhd, col, i, &dt, curd);
  952.         }
  953.         MOS_disp(1);
  954.     }
  955.     ICN_mos(0);
  956. }
  957.  
  958. static int SUB_tree(int mx, int my) {
  959.     int        sc, xx, yy, psc = -1;
  960.     char    mb;
  961.     
  962.     if (TRIGN)
  963.         return 0;
  964.     
  965.     xx = cv->wx + 7;
  966.     yy = cv->wy + 30 + 20 * cv->drw;
  967.     sc = Where_tree(mx, my);
  968.     do {
  969.         if (psc != sc) {
  970.             if (psc != -1)
  971.                 EGB_rev(1, xx, yy + psc * 20, xx + 223, yy + psc * 20 + 19);
  972.             if (sc != -1)
  973.                 EGB_rev(1, xx, yy + sc * 20, xx + 223, yy + sc * 20 + 19);
  974.         }
  975.         psc = sc;
  976.         
  977.         MOS_rdpos(&mb, &mx, &my);
  978.         sc = Where_tree(mx, my);
  979.     } while (mb & 1);
  980.     
  981.     if (psc != -1) {
  982.         curd = trhd + psc;
  983.         ICN_mos(1);
  984.         if (!TR_Search_curd(0, &curd, cv->dirbuf, &dt)) {
  985.             errord();
  986.         } else if (chdir(cv->dirbuf)) {
  987.             errord();
  988.         } else if (FSW_Draw_path(0, &diroff)) {
  989.             errord();
  990.         } else {
  991.             EGB_rev(1, xx, yy + psc * 20, xx + 223, yy + psc * 20 + 19);
  992.             Tree(1);
  993.             filehd = 0;
  994.             if (FSW_Draw_file(0, filehd, &gf))
  995.                 return -1;
  996.             FSW_Draw_scrollB(filehd, gf.nfiles);
  997.         }
  998.         ICN_mos(0);
  999.     }
  1000.     
  1001.     return 0;
  1002. }
  1003.  
  1004. static int Where_tree(int mx, int my) {
  1005.     int        ret;
  1006.     
  1007.     mx -= cv->wx;
  1008.     my -= cv->wy;
  1009.     if (mx < 7 || 230 < mx || my < 30 + 20 * cv->drw || 309 + 20 * cv->drw < my) {
  1010.         ret = -1;
  1011.     } else {
  1012.         int        sc;
  1013.         
  1014.         sc = (my - (30 + 20 * cv->drw)) / 20;
  1015.         if (trhd + sc < dt.numd)
  1016.             ret = sc;
  1017.         else
  1018.             ret = -1;
  1019.     }
  1020.     
  1021.     return ret;
  1022. }
  1023.